<?php
/**
 * @Author: king
 * @Date:   2019-01-20 19:00:48
 * @Last Modified by:   king
 * @Last Modified time: 2019-06-06 18:26:34
 */

use Aliyun\Api\Sms\Request\V20170525\SendSmsRequest;
use Aliyun\Core\Config;
use Aliyun\Core\DefaultAcsClient;
use Aliyun\Core\Profile\DefaultProfile;
use App\Models\Api\Orders;
use App\Models\Api\Recode;
use App\Models\Api\AstroSetting;
use App\Models\Api\Rectification;
use BaiduAip\AipContentCensor;
use App\Wen\Utils\BaiduUtils;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Queue;

/**
 * 发起HTTPS请求
 */
function curl_post($url, $data, $header, $type = 'json', $post = 1)
{
    $ch  = curl_init();
    $res = curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, $post);
    if ($post) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $result = curl_exec($ch);
    //连接失败
    if ($result == false) {
        if ($type == 'json') {
            $result = response()->json(['code' => 10052, 'msg' => 'Network error.']);
        } else {
            $result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Response><code>10052</code><msg>网络错误</msg></Response>";
        }
    }
    curl_close($ch);
    return $result;
}

// 应用公共文件
function round_str($len = 128)
{
    // 密码字符集，可任意添加你需要的字符
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';

    $password = '';
    for ($i = 0; $i < $len; $i++) {
        // 这里提供两种字符获取方式
        // 第一种是使用 substr 截取$chars中的任意一位字符；
        // 第二种是取字符数组 $chars 的任意元素
        // $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
        $password .= $chars[mt_rand(0, strlen($chars) - 1)];
    }
    return $password;
}

/**
 * 是否为夏令时时间
 * @return boolean [description]
 */
function isSummerTime($hour, $minute, $second, $month, $day, $year)
{
    // 夏令时时间  6个区间
    // 1.      1986年5月4日（凌晨2点）至9月14日（凌晨2点）；
    // 2.      1987年4月12日（凌晨2点）至9月13日（凌晨2点）；
    // 3.      1988年4月10日（凌晨2点）至9月11日（凌晨2点），
    // 4.      1989年4月16日（凌晨2点）至9月17日（凌晨2点），
    // 5.      1990年4月15日（凌晨2点）至9月16日（凌晨2点），
    // 6.      1991年4月14日（凌晨2点）至9月15日（凌晨2点）。
    $start_time = [
        mktime(2, 0, 0, 5, 4, 1986),
        mktime(2, 0, 0, 4, 12, 1987),
        mktime(2, 0, 0, 4, 10, 1988),
        mktime(2, 0, 0, 4, 16, 1989),
        mktime(2, 0, 0, 4, 15, 1990),
        mktime(2, 0, 0, 4, 14, 1991),
    ];
    $end_time = [
        mktime(2, 0, 0, 9, 14, 1986),
        mktime(2, 0, 0, 9, 13, 1987),
        mktime(2, 0, 0, 9, 11, 1988),
        mktime(2, 0, 0, 9, 17, 1989),
        mktime(2, 0, 0, 9, 16, 1990),
        mktime(2, 0, 0, 9, 15, 1991),
    ];

    $time = mktime($hour, $minute, $second, $month, $day, $year);

    for ($i = 0; $i < 6; $i++) {
        if ($time > $start_time[$i] && $time < $end_time[$i]) {
            return true;
        }

    }

    return false;
}

/**
 * 对二维数组重新排序
 * @param array $array
 * @param string $sort_key
 * @param string $sort
 * @return array
 */
function resort(array $array, string $sort_key, string $sort = 'DESC')
{
    if (!empty($array)) {
        foreach ($array as $k1 => $d1) {
            foreach ($array as $k2 => $d2) {
                if ($k1 < $k2) {
                    if ($sort === 'DESC' && $array[$k1][$sort_key] < $array[$k2][$sort_key]) {
                        $temp       = $array[$k1];
                        $array[$k1] = $array[$k2];
                        $array[$k2] = $temp;
                    } elseif ($sort === 'ASC' && $array[$k1][$sort_key] > $array[$k2][$sort_key]) {
                        $temp       = $array[$k1];
                        $array[$k1] = $array[$k2];
                        $array[$k2] = $temp;
                    }
                }

            }
        }
    }
    return $array;
}

/**
 * 对三维数组重新排序
 * @param array $array
 * @param string $sort_key name1.name2
 * @param string $sort
 * @return array
 */
function resort3(array $array, string $sort_key, string $sort = 'DESC')
{
    if (!empty($array))
    {
        $sort = strtoupper($sort);
        $sortKeyArr = explode('.', $sort_key);
        if (count($sortKeyArr) > 1)
        {
            $sortKey1 = $sortKeyArr[0];
            $sortKey2 = $sortKeyArr[1];
            foreach ($array as $k1 => $d1)
            {
                foreach ($array as $k2 => $d2)
                {
                    if ($k1 < $k2)
                    {
                        if ($sort === 'DESC' && $array[$k1][$sortKey1][$sortKey2] < $array[$k2][$sortKey1][$sortKey2])
                        {
                            $temp = $array[$k1];
                            $array[$k1] = $array[$k2];
                            $array[$k2] = $temp;
                        } elseif ($sort === 'ASC' && $array[$k1][$sortKey1][$sortKey2] > $array[$k2][$sortKey1][$sortKey2])
                        {
                            $temp = $array[$k1];
                            $array[$k1] = $array[$k2];
                            $array[$k2] = $temp;
                        }
                    }
                }
            }
        } else
        {
            foreach ($array as $k1 => $d1)
            {
                foreach ($array as $k2 => $d2)
                {
                    if ($k1 < $k2)
                    {
                        if ($sort === 'DESC' && $array[$k1][$sort_key] < $array[$k2][$sort_key])
                        {
                            $temp = $array[$k1];
                            $array[$k1] = $array[$k2];
                            $array[$k2] = $temp;
                        } elseif ($sort === 'ASC' && $array[$k1][$sort_key] > $array[$k2][$sort_key])
                        {
                            $temp = $array[$k1];
                            $array[$k1] = $array[$k2];
                            $array[$k2] = $temp;
                        }
                    }
                }
            }
        }
    }
    return $array;
}
/**
 * 检测成相
 * @param array $planet1 成相星体组1
 * @param array $planet2 成相星体组2
 * @param array $phase_e 成相度数组 为空时检测是否成相
 * @param array $planets 需要检测的行星数据
 * @param integer $orb_limit 限制容许度
 * @return bool 是否满足成相条件
 */
function checkPhase(array $planet1 = [], array $planet2 = [], array $phase_e = [], array $planets = [], $orb_limit = -10)
{
    $result = false;
    // 若星体组为空  或  行星数据为空时 直接返回false
    if (empty($planet1) || empty($planet2) || empty($planets)) {
        return $result;
    }
    // 遍历星体组1
    foreach ($planet1 as $p1) {
        // 遍历星体组2
        foreach ($planet2 as $p2) {
            // 成相
            if (isset($planets[$p1]['phase'][$p1 . '-' . $p2])) {
                // 若只检测是否成相
                if (empty($phase_e)) {
                    // 限制容许度 并满足该条件
                    if ($orb_limit >= 0 && $planets[$p1]['phase'][$p1 . '-' . $p2]['phase_orb'] <= $orb_limit) {
                        $result = true;
                    } // 限制容许度 不满足条件
                    elseif ($orb_limit >= 0 && $planets[$p1]['phase'][$p1 . '-' . $p2]['phase_orb'] > $orb_limit) {
                        $result = false;
                    } //  不限容许度
                    elseif ($orb_limit < 0) {
                        $result = true;
                    }
                } // 检测是否为具体相位
                elseif (in_array($planets[$p1]['phase'][$p1 . '-' . $p2]['phase_e'], $phase_e)) {
                    // 限制容许度 并满足该条件
                    if ($orb_limit >= 0 && $planets[$p1]['phase'][$p1 . '-' . $p2]['phase_e'] <= $orb_limit) {
                        $result = true;
                    } // 限制容许度 不满足条件
                    elseif ($orb_limit >= 0 && $planets[$p1]['phase'][$p1 . '-' . $p2]['phase_e'] > $orb_limit) {
                        $result = false;
                    } //  不限容许度
                    elseif ($orb_limit < 0) {
                        $result = true;
                    }
                }
            }
        }
    }
    return $result;
}

/**
 * 检测落座落宫
 * @param array $planet 星体
 * @param array $data 落宫组或落座组
 * @param array $planets 星体数据
 * @param string $type 具体检测落宫 或 检测落座
 * @param string $limit 之一 || 均
 * @return bool 是否成立
 */
function checkSignHouse(array $planet = [], array $data = [], array $planets = [], string $type = 'house', string $limit = 'one')
{
    $result = false;

    if (empty($planet) || empty($data) || empty($planets)) {
        return $result;
    }
    $not_limit = true;

    foreach ($planet as $p) {
        if (!$result && $not_limit && isset($planets[$p])) {
            if ($limit == 'one'
                &&
                (
                    ($type === 'house' && in_array($planets[$p]['in_house_id'], $data))
                    || ($type === 'sign' && in_array($planets[$p]['in_sign_id'], $data))
                )
            ) {
                $result = true;
            } elseif ($limit != 'one'
                &&
                (
                    ($type === 'house' && !in_array($planets[$p]['in_house_id'], $data))
                    || ($type === 'sign' && !in_array($planets[$p]['in_sign_id'], $data))
                )
            ) {
                $not_limit = false;
            }
        }
    }

    if (($limit === 'one' && $result === true) || $limit != 'one' && $not_limit === true) {
        return true;
    }

    return false;
}

/**
 * 检测是否为四象星座
 * @param array $planet 星体组
 * @param array $data 四象星座id组  [1,2,3,0] 表示火土风水
 * @param array $planets 星体数据
 * @param string $limit 之一 || 均
 * @return bool 是否成立
 */
function checkQuadrature(array $planet = [], array $data = [], array $planets = [], string $limit = 'one')
{
    $result = false;

    if (empty($planet) || empty($data) || empty($planets)) {
        return $result;
    }

    $not_limit = true;

    foreach ($planet as $p) {
        if (in_array($planets[$p]['in_sign_id'] % 4, $data)) {
            $result = true;
        } else {
            $not_limit = false;
        }
    }
    if ($limit === 'one') {
        return $result;
    } else {
        return $not_limit;
    }
}

/**
 * 行星落座
 * @return int 1-12
 *
 */
function InWhichSign($longitude = 0)
{
     $sign = (int)ceil($longitude / 29.999999999999);
    if ($sign < 1) $sign = 1;
    elseif ($sign > 12) $sign = 12;
    return $sign;
 // 上升白羊0°时 0/30=0  特加此判断
}

/**
 * 行星落宫
 * @return int 1-12
 *
 */
function InWhichHouse($longitude = 0, $house = array())
{
    $house[13] = $house[1];
    $in_house  = 12;
    for ($j = 1; $j <= 12; $j++) {
        $pl     = $longitude + (1 / 36000);
        $h_now  = $house[$j];
        $h_next = $house[$j + 1];

        if ($j < 12 && $h_now > $h_next) {
            if (($pl >= $h_now && $pl < 360) || ($pl < $h_next && $pl >= 0)) {
                $in_house = $j;
            }
        }

        if ($j == 12 && ($h_now > $house[1])) {
            if (($pl >= $h_now && $pl < 360) || ($pl < $house[1] && $pl >= 0)) {
                $in_house = $j;
            }
        }

        if (($pl >= $h_now) && ($pl < $h_next && ($j < 12))) {
            $in_house = $j;
        }

        if (($pl >= $h_now) && ($pl < $house[1]) && ($j == 12)) {
            $in_house = $j;
        }

    }
    return $in_house;
}

//1、Unix时间戳转日期
function unixtime_to_date($unixtime, $format = "Y-m-d H:i:s", $timezone = 'PRC')
{
    $datetime = new DateTime("@$unixtime"); //DateTime类的bug，加入@可以将Unix时间戳作为参数传入
    $datetime->setTimezone(new DateTimeZone($timezone));
    return $datetime->format($format);
}

//2、日期转Unix时间戳
function date_to_unixtime($date, $format = "U", $timezone = 'PRC')
{
    $datetime = new DateTime($date, new DateTimeZone($timezone));
    return $datetime->format($format);
}

function Crunch($x)
{
    if ($x >= 0) {
        $y = $x - floor($x / 360) * 360;
    } else {
        $y = 360 + ($x - ((1 + floor($x / 360)) * 360));
    }

    return $y;
}

function mod360($x)
{
    return $x - (floor($x / 360) * 360);
}

function Get_OB_Ecl($jd)
{
    // fetch mean obliquity
    $t = ($jd - 2451545) / 36525;

    $epsilon = 23.43929111;
    $epsilon = $epsilon - (46.815 * $t / 3600);
    $epsilon = $epsilon - (0.00059 * $t * $t / 3600);
    $epsilon = $epsilon + (0.001813 * $t * $t * $t / 3600);
    return $epsilon;
}

/**
 * 私钥加密
 */
function privEncrypt($data)
{
    if (!is_string($data)) {
        return null;
    }

    $private_key = openssl_pkey_get_private(config('private_key'));
    return openssl_private_encrypt($data, $encrypted, $private_key) ? base64_encode($encrypted) : null;
}

/**
 * 私钥解密
 */
function privDecrypt($encrypted)
{
//    dump($encrypted);
    if (!is_string($encrypted)) {
        return null;
    }

    $private_key = openssl_pkey_get_private(config('private_key'));
//    dump($private_key);
    //    dump(openssl_private_decrypt(base64_decode($encrypted), $decrypted, $private_key));
    //    dump($decrypted);
    return (openssl_private_decrypt(base64_decode($encrypted), $decrypted, $private_key)) ? $decrypted : null;
}

/**
 * 生成float随机数
 * @param int $min 最小值
 * @param int $max 最大值
 * @return int
 */
function randomFloat($min = 0, $max = 1)
{
    return $min + mt_rand() / mt_getrandmax() * ($max - $min);
}

/**
 * 获取基础时间
 * @param null $year
 * @param null $month
 * @param null $day
 * @param null $hour
 * @param null $minute
 * @param int $timezone
 * @return false|int
 */
function get_base_time($time = null, $timezone = 8)
{
    // 夏令时时间  6个区间
    $start_time = [
        mktime(2, 0, 0, 5, 4, 1986), // 1. 1986年5月4日（凌晨2点）至9月14日（凌晨2点）；
        mktime(2, 0, 0, 4, 12, 1987), // 2.1987年4月12日（凌晨2点）至9月13日（凌晨2点）；
        mktime(2, 0, 0, 4, 10, 1988), // 3.1988年4月10日（凌晨2点）至9月11日（凌晨2点），
        mktime(2, 0, 0, 4, 16, 1989), // 4.1989年4月16日（凌晨2点）至9月17日（凌晨2点），
        mktime(2, 0, 0, 4, 15, 1990), // 5.1990年4月15日（凌晨2点）至9月16日（凌晨2点），
        mktime(2, 0, 0, 4, 14, 1991), // 6.1991年4月14日（凌晨2点）至9月15日（凌晨2点）。
    ];
    $end_time = [
        mktime(2, 0, 0, 9, 14, 1986),
        mktime(2, 0, 0, 9, 13, 1987),
        mktime(2, 0, 0, 9, 11, 1988),
        mktime(2, 0, 0, 9, 17, 1989),
        mktime(2, 0, 0, 9, 16, 1990),
        mktime(2, 0, 0, 9, 15, 1991),
    ];

    for ($i = 0; $i < 6; $i++) {
        if ($time > $start_time[$i] && $time < $end_time[$i]) {
            $time -= 3600; // 夏令时，减一小时
            break;
        }
    }
    // 转换成格林尼治时间
    $time -= $timezone * 3600;

    return intval($time);
}

/**
 * 入星座度数
 * 如：18°2'26''  || 18°3′
 * @return [type] [description]
 */
function in_sign_deg($deg, $get_sec = false)
{
    $longitude   = $deg;
    $sign_id     = floor($longitude / 30);
    $pos_in_sign = $longitude - ($sign_id * 30);
    $deg         = floor($pos_in_sign);
    $full_min    = ($pos_in_sign - $deg) * 60;
    $min         = floor($full_min);
    $sec         = round(($full_min - $min) * 60);
    if ($deg < 10) {
        $deg = '    ' . $deg;
    }

    if ($min < 10) {
        $min = '0' . $min;
    }

    if ($sec < 10) {
        $sec = '0' . $sec;
    }

    if (!$get_sec) {
        // 四舍五入
        if ($sec >= 30) {
            $min++;
        }

        if ($min == 60) {
            $min = 0;
            $deg++;
        }
        return $deg . '°' . $min . "′";
    }
    return $deg . '°' . $min . "′" . $sec . '″';
}

/**
 * 获取用户星盘配置信息
 * @param null $uid 用户id
 * @param string $chart 当前看的是哪个星盘  如：天象盘、本命盘
 * @param int $tid
 * @return array
 * @throws db\exception\DataNotFoundException
 * @throws db\exception\ModelNotFoundException
 * @throws exception\DbException
 */
function get_astro_setting($uid = null, $chart = 'now', $tid = 1)
{
    $setting = DB::table('astro_setting_' . $chart)->select('tid', 'asp_orb_all', 'asps_display', 'planets_display', 'planet_orb_all', 'h_sys')
        ->where(['uid' => $uid, 'tid' => $tid, 'status' => 0])
        ->first();

    if (!$setting || empty($setting)) {
        // 去老库里面查询
        $setting = AstroSetting::where(['uid' => $uid, 'tid' => $tid])->orderBy('use_time', 'DESC')->first([$chart])->toArray();
        
        if (empty($setting) || $setting[$chart] === null) {
            $setting1 = [
                'now'                       => [
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'natal'                     => [
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'transits'                  => [
                    'asp_orb_all'     => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                    'style'           => 'cn',
                    'firdaria'        => 'default',
                ],
                'thirdprogressed'           => [
                    //            'asp_orb_all'=> [0=>3,60=>2,90=>3,120=>3,180=>3,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'thirdprogressedvsnatal'    => [
                    'asp_orb_all'     => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                    'style'           => 'cn',
                    'firdaria'        => 'default',
                ],
                'progressions'              => [
                    //            'asp_orb_all'=> [0=>2,60=>2,90=>2,120=>2,180=>2,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'progressionsvsnatal'       => [
                    'asp_orb_all'     => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                    'style'           => 'cn',
                    'firdaria'        => 'default',
                ],
                'solar'                     => [
                    'asp_orb_all'     => [0 => 1, 60 => 0, 90 => 1, 120 => 0, 180 => 1, 30 => 0, 150 => 1, 45 => 1, 135 => 1, 72 => 0, 144 => 0],
                    'asps_display'    => [0, 45, 90, 135, 180],
                    'planets_display' => '111111111100100001111',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'solar_return'              => [
                    //            'asp_orb_all'=> [0=>8,60=>6,90=>7,120=>7,180=>7,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'lunar_return'              => [
                    //            'asp_orb_all'=> [0=>4,60=>2,90=>3,120=>3,180=>3.5,30=>0.5,150=>1,45=>1,135=>1,72=>0.5,144=>0.5],
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'firdaria'                  => [
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                    'firdaria'        => 'default',
                ],
                'profection'                => [
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'synastry'                  => [
                    'asp_orb_all'     => [0 => 6, 60 => 4, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'composite'                 => [
                    //            'asp_orb_all'=> [0=>4,60=>3,90=>4,120=>4,180=>4,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'composite_thirdprogressed' => [
                    //            'asp_orb_all'=> [0=>5,60=>4,90=>5,120=>5,180=>5,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'composite_progressions'    => [
                    //            'asp_orb_all'=> [0=>4,60=>3,90=>4,120=>4,180=>4,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                    'style'           => 'cn',
                ],
                'davison'                   => [
                    //            'asp_orb_all'=> [0=>6,60=>5,90=>6,120=>6,180=>6,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'marks'                     => [
                    //            'asp_orb_all'=> [0=>6,60=>5,90=>6,120=>6,180=>6,30=>1,150=>2,45=>2,135=>2,72=>2,144=>2],
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'divination'                => [
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
            ];
            $setting2 = [
                'now'                       => [
                    'asp_orb_all'     => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys'           => 'p',
                ],
                'natal'                     => [
                    'asp_orb_all'     => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys'           => 'p',
                ],
                'transits'                  => [
                    'asp_orb_all'     => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'thirdprogressed'           => [
                    'asp_orb_all'     => [0 => 3, 60 => 2, 90 => 3, 120 => 3, 180 => 3, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'thirdprogressedvsnatal'    => [
                    'asp_orb_all'     => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'progressions'              => [
                    'asp_orb_all'     => [0 => 2, 60 => 2, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'progressionsvsnatal'       => [
                    'asp_orb_all'     => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'solar'                     => [
                    'asp_orb_all'     => [0 => 1, 60 => 0, 90 => 1, 120 => 0, 180 => 1, 30 => 0, 150 => 1, 45 => 1, 135 => 1, 72 => 0, 144 => 0],
                    'asps_display'    => [0, 45, 90, 135, 180],
                    'planets_display' => '111111111100100001111',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'solar_return'              => [
                    'asp_orb_all'     => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys'           => 'p',
                ],
                'lunar_return'              => [
                    'asp_orb_all'     => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'firdaria'                  => [
                    'asp_orb_all'     => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys'           => 'p',
                    'firdaria'        => 'default',
                ],
                'profection'                => [
                    'asp_orb_all'     => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys'           => 'p',
                ],
                'synastry'                  => [
                    'asp_orb_all'     => [0 => 6, 60 => 4, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100100001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'composite'                 => [
                    'asp_orb_all'     => [0 => 4, 60 => 3, 90 => 4, 120 => 4, 180 => 4, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'composite_thirdprogressed' => [
                    'asp_orb_all'     => [0 => 5, 60 => 4, 90 => 5, 120 => 5, 180 => 5, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'composite_progressions'    => [
                    'asp_orb_all'     => [0 => 4, 60 => 3, 90 => 4, 120 => 4, 180 => 4, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'davison'                   => [
                    'asp_orb_all'     => [0 => 6, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'marks'                     => [
                    'asp_orb_all'     => [0 => 6, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'divination'                => [
                    'asp_orb_all'     => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111100000001001',
                    'planet_orb_all'  => [3, 2.5, 1, 1, 1, 1.5, 1.5, 1, 1, 0.5],
                    'h_sys'           => 'p',
                ],
            ];
            $setting3 = [
                'now'                       => [
                    'asp_orb_all'     => [0 => 7, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180, 30, 150],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'natal'                     => [
                    'asp_orb_all'     => [0 => 7, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180, 30, 150],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'transits'                  => [
                    'asp_orb_all'     => [0 => 2, 60 => 1, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'thirdprogressed'           => [
                    'asp_orb_all'     => [0 => 3, 60 => 2, 90 => 3, 120 => 3, 180 => 3, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'thirdprogressedvsnatal'    => [
                    'asp_orb_all'     => [0 => 3, 60 => 2, 90 => 3, 120 => 3, 180 => 3, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'progressions'              => [
                    'asp_orb_all'     => [0 => 2, 60 => 2, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'progressionsvsnatal'       => [
                    'asp_orb_all'     => [0 => 2, 60 => 2, 90 => 2, 120 => 2, 180 => 2, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'solar'                     => [
                    'asp_orb_all'     => [0 => 1, 60 => 0, 90 => 1, 120 => 0, 180 => 1, 30 => 0, 150 => 1, 45 => 1, 135 => 1, 72 => 0, 144 => 0],
                    'asps_display'    => [0, 45, 90, 135, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'solar_return'              => [
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'lunar_return'              => [
                    'asp_orb_all'     => [0 => 4, 60 => 2, 90 => 3, 120 => 3, 180 => 3.5, 30 => 0.5, 150 => 1, 45 => 1, 135 => 1, 72 => 0.5, 144 => 0.5],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'firdaria'                  => [
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                    'style'           => 'cn',
                    'firdaria'        => 'default',
                ],
                'profection'                => [
                    'asp_orb_all'     => [0 => 8, 60 => 6, 90 => 7, 120 => 7, 180 => 7, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'synastry'                  => [
                    'asp_orb_all'     => [0 => 6, 60 => 4, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'composite'                 => [
                    'asp_orb_all'     => [0 => 4, 60 => 3, 90 => 4, 120 => 4, 180 => 4, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'composite_thirdprogressed' => [
                    'asp_orb_all'     => [0 => 5, 60 => 4, 90 => 5, 120 => 5, 180 => 5, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'composite_progressions'    => [
                    'asp_orb_all'     => [0 => 4, 60 => 3, 90 => 4, 120 => 4, 180 => 4, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'davison'                   => [
                    'asp_orb_all'     => [0 => 6, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'marks'                     => [
                    'asp_orb_all'     => [0 => 6, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
                'divination'                => [
                    'asp_orb_all'     => [0 => 7, 60 => 5, 90 => 6, 120 => 6, 180 => 6, 30 => 1, 150 => 2, 45 => 2, 135 => 2, 72 => 2, 144 => 2],
                    'asps_display'    => [0, 60, 90, 120, 180, 30, 150],
                    'planets_display' => '111111111111111001001',
                    'planet_orb_all'  => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    'h_sys'           => 'p',
                ],
            ];

            if ($tid == 1) {
                $setting = ($setting1[$chart]);
            } elseif ($tid == 2) {
                $setting = ($setting2[$chart]);
            } elseif ($tid == 3) {
                $setting = ($setting3[$chart]);
            }

//            dump($setting);
            $setting['tid'] = $tid;

        } // 若原来有设置，则自动添加到新的数据表中
        elseif (!empty($setting) && $setting[$chart] != null) {
            $divination                 = json_decode($setting[$chart], true);
            $db_data['tid']             = $tid;
            $db_data['uid']             = $uid;
            $db_data['asp_orb_all']     = json_encode($divination['asp_orb_all']);
            $db_data['asps_display']    = json_encode($divination['asps_display']);
            $db_data['planet_orb_all']  = json_encode($divination['planet_orb_all']);
            $db_data['planets_display'] = $divination['planets_display'];
            $db_data['create_time']     = time();
//            DB::table('app_astro_setting_'.$chart)->insertGetId($db_data); // 存入新版数据表
            $divination['tid'] = $tid;
            $setting           = $divination;
        }
    } else {
        $setting['asp_orb_all']    = json_decode($setting['asp_orb_all'], true);
        $setting['asps_display']   = json_decode($setting['asps_display'], true);
        $setting['planet_orb_all'] = json_decode($setting['planet_orb_all'], true);
    }
//    dump('uid:===='.$uid.'====tid:'.$tid);
    //    dump($setting);
    //    exit;
    return $setting;
}

/**
 * 相位出入相
 * @param $asp int 相位度数
 * @param $deg1 float 行星度数1
 * @param $deg2 float 行星度数2
 * @param $speed1  float 速度1
 * @param $speed2 float 速度2
 * @param $vs 1=>行星1为本命 2=> 行星2为本命     本命盘速度为0
 * @return bool true 为入相  false 为出相
 */
function phase_in_or_out($asp, $deg1, $deg2, $speed1, $speed2, $vs = 0)
{
    $da = abs($deg1 - $deg2);

    if ($da > 180) {
        $da = 360 - $da;
    }

    // VS 本命盘计算出入相位
    if ($vs) {
        if ($vs == 1) {
            $fixed  = $deg1;
            $speed1 = 0;
        } elseif ($vs == 2) {
            $fixed  = $deg2;
            $speed2 = 0;
        }
        $accurate_deg1 = $fixed + $asp;
        $accurate_deg2 = $fixed - $asp;

    }
    if (abs($speed1) > abs($speed2)) {
        $s3  = $speed1 - $speed2;
        $da3 = abs($deg1 - $deg2 + $s3);
    } else {
        $s3  = $speed2 - $speed1;
        $da3 = abs($deg1 - $deg2 - $s3);
    }
    if ($da3 > 180) {
        $da3 = 360 - $da3;
    }

    if (abs($da - $asp) > abs($da3 - $asp)) {
        return true;
    }

    return false;

}

/**
 * 发送短信接口
 * 文档地址 https://help.aliyun.com/document_detail/55491.html?spm=5176.doc55491.6.560.0KUKny
 * @param $mobile int   手机号
 * @param $params array   模板替换参数
 * @param $code string 短信模版
 * @return mixed    code = OK 表示完成
 */
function sendSms($mobile, $params, $code)
{

    //获取短信配置
    $appkey    = config('aliyun.dayu_appkey');
    $secretkey = config('aliyun.dayu_secretkey');
    $name      = config('aliyun.dayu_name');

    Config::load();
    $templateParam = $params;
    $product       = "Dysmsapi";
    $domain        = "dysmsapi.aliyuncs.com";
    $region        = "cn-hangzhou";

    $profile = DefaultProfile::getProfile($region, $appkey, $secretkey);
    DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
    $acsClient = new DefaultAcsClient($profile);
    $request   = new SendSmsRequest();
    $request->setPhoneNumbers($mobile);
    $request->setSignName($name);
    $request->setTemplateCode($code);
    if ($templateParam) {
        $request->setTemplateParam(json_encode($templateParam, JSON_UNESCAPED_UNICODE));
    }

    $acsResponse = $acsClient->getAcsResponse($request);
    $result      = json_decode(json_encode($acsResponse), true);
    return $result;
}

/**
 * 加入队列
 * @param $task
 * @param $jobData
 * @param $queue
 * @param int $delay
 */
function queuePush($w, $jobData, $queue, $delay = 0)
{
    /*$isUseRabbitmq=0;//是否使用Rabbitmq，1：使用；0不使用；
    if ($isUseRabbitmq){
    require_once VENDOR_PATH .'/App/Tools/RabbitmqRectificationProducer.php';

    RabbitmqRectificationProducer::sendMessage($delay,$jobData);
    }else{//使用think-queue+redis的方式实现消息队列*/
    if ($delay <=0 ) {
        try
        {
            Queue::push($task, $jobData, $queue); // 立即执行
        } catch (\Exception $e) {
            // 加入立即执行队列失败
            \Log::info('加入立即执行队列失败:' . var_export($jobData, true));
        }
    } else {
        try
        {
            Queue::later($delay, $task, $jobData, $queue); // 延迟15分钟执行
        } catch (\Exception $e) {
            // 加入立即延时队列失败
            \Log::info('加入立即延时队列失败:' . var_export($jobData, true));
        }
    }
}
//}
/**
 * 检查档案时间格式
 * @param $year
 * @param $month
 * @param $day
 * @param $hour
 * @param $minute
 * @param $timezone
 */
function checkRecodeData($year = null, $month = null, $day = null, $hour = null, $minute = null, $timezone = null)
{
    // 年份限制 1000 - 2999
    if ($year === null || $year < 1000 || $year > 2999) {
//            echo $year;
        echo json_encode(['code' => 0, 'msg' => 'Year Invalid.']);
        exit;
    }
    // 月份限制 1-12
    if ($month === null || $month < 0 || $month > 12) {
        echo json_encode(['code' => 0, 'msg' => 'Month Invalid.']);
        exit;
    }
    // 日期限制 1-31
    if ($day === null || $day < 0 || $day > 31
        || (is_bissextile($year) && $month == 2 && $day > 29)
        || (!is_bissextile($year) && $month == 2 && $day > 28)
        || (in_array($month, [4, 6, 9, 11]) && $day > 30)) {
        echo json_encode(['code' => 0, 'msg' => 'Day Invalid.']);
        exit;
    }
    // 小时限制 0-23
    if ($hour === null || $hour < 0 || $hour > 23) {
        echo json_encode(['code' => 0, 'msg' => 'Hour Invalid.']);
        exit;
    }
    // 分钟限制 0-59
    if ($minute === null || $minute < 0 || $minute > 59) {
        echo json_encode(['code' => 0, 'msg' => 'Minute Invalid.']);
        exit;
    }
    if ($timezone < -12 || $timezone > 12) {
        echo json_encode(['code' => 0, 'msg' => 'Timezone Invalid.']);
        exit;
    }
}

/**
 * 判断是否为闰年
 * 闰年 true || 平年 false
 * @param null $year
 * @return bool
 */
function is_bissextile($year = null)
{
    if ($year === null) {
        echo json_encode(['code' => 10719, 'msg' => 'Year Invalid.']);
        exit;
    }
    if ($year % 400 === 0 || ($year % 100 !== 0 && $year % 4 === 0)) {
        return true;
    }
    return false;
}

/**
 * 检测某星体度数是否在两个度数之间
 * @param $deg
 * @param $deg1
 * @param $deg2
 * @param $orb int 相差多少度为特殊情况（即$deg1 在白羊座0度附近）
 * @return bool
 */
function isBetweenIn($deg, $deg1, $deg2, $orb = 270)
{
    // $deg1 = 356  $deg2 = 2  =>  362
    if ($deg1 > $deg2 && $deg1 - $deg2 > $orb) {
        // $deg = 3   =>   363
        if ($deg1 - $deg > $orb && $deg > $deg2) {
            return true;
        } // $deg = 358
        elseif ($deg > $deg1) {
            return true;
        }
    } // $deg2 = 356  $deg1 = 2  =>  362
    elseif ($deg1 < $deg2 && $deg2 - $deg1 > $orb) {
        // $deg = 3   =>   363
        if ($deg2 - $deg > $orb && $deg > $deg1) {
            return true;
        } // $deg = 358
        elseif ($deg > $deg2) {
            return true;
        }
    } else {
        if (($deg > $deg2 && $deg < $deg1) || ($deg > $deg1 && $deg < $deg2)) {
            return true;
        }
    }
    return false;
}

/**
 * 通用化API接口数据输出
 * @param int $code 业务状态码
 * @param string $msg 信息提示
 * @param array $data 数据
 * @param int $httpCode http状态码
 * @return
 */
function show($code, $msg, $data = [])
{
   $data =[
            'status'  => ($code == 200) ? true : false,
            'code'    => $code,
            'message' => $msg?: config('errorcode.code')[(int) $code],
            'data'    => $data,
        ];

    return response()->json($data,200, [], JSON_INVALID_UTF8_IGNORE);
}

/**判断是否为闰年
 * @param null $year
 * @return bool
 */
function is_bisextile($year = null)
{
    if ($year === null) {
        echo json_encode(['code' => 10719, 'msg' => 'Year Invalid.']);
        exit;
    }
    if ($year % 400 === 0 || ($year % 100 !== 0 && $year % 4 === 0)) {
        return true;
    }
    return false;
}

/**获取档案星盘数据
 * @param null $year
 * @param null $month
 * @param null $day
 * @param null $hour
 * @param null $minute
 * @param null $longitude
 * @param null $latitude
 * @param int $timezone
 * @param string $h_sys
 * @return array
 */
function getTheRecodeAstro($year = null, $month = null, $day = null, $hour = null, $minute = null, $longitude = null, $latitude = null, $timezone = 8, $h_sys = 'p')
{
    $time      = getTheBaseTime($year, $month, $day, $hour, $minute, $timezone);
    $utdatenow = strftime("%d.%m.%Y", $time);
    $utnow     = strftime("%H:%M:%S", $time);

    exec(config('astrolog.prefix') . " -b{$utdatenow} -ut{$utnow} -p0123456789DAtHt -eswe -house{$longitude},{$latitude},{$h_sys} -flds -g, -head", $out);

    $data = getOriginalData($out);

    $result         = [];
    $result['sun']  = InWhichSign($data['p1'][0]) . '-' . InWhichHouse($data['p1'][0], $data['hc1']) . '-' . $data['p1'][0];
    $result['moon'] = InWhichSign($data['p1'][1]) . '-' . InWhichHouse($data['p1'][1], $data['hc1']) . '-' . $data['p1'][1];
    $result['merc'] = InWhichSign($data['p1'][2]) . '-' . InWhichHouse($data['p1'][2], $data['hc1']) . '-' . $data['p1'][2];
    $result['venu'] = InWhichSign($data['p1'][3]) . '-' . InWhichHouse($data['p1'][3], $data['hc1']) . '-' . $data['p1'][3];
    $result['mars'] = InWhichSign($data['p1'][4]) . '-' . InWhichHouse($data['p1'][4], $data['hc1']) . '-' . $data['p1'][4];
    $result['jupi'] = InWhichSign($data['p1'][5]) . '-' . InWhichHouse($data['p1'][5], $data['hc1']) . '-' . $data['p1'][5];
    $result['satu'] = InWhichSign($data['p1'][6]) . '-' . InWhichHouse($data['p1'][6], $data['hc1']) . '-' . $data['p1'][6];
    $result['non']  = InWhichSign($data['p1'][12]) . '-' . InWhichHouse($data['p1'][12], $data['hc1']) . '-' . $data['p1'][12];
    $result['lili'] = InWhichSign($data['p1'][11]) . '-' . InWhichHouse($data['p1'][11], $data['hc1']) . '-' . $data['p1'][11];
    $result['juno'] = InWhichSign($data['p1'][13]) . '-' . InWhichHouse($data['p1'][13], $data['hc1']) . '-' . $data['p1'][13];
    $result['asc']  = InWhichSign($data['p1'][17]) . '-' . InWhichHouse($data['p1'][17], $data['hc1']) . '-' . $data['p1'][17];
    $result['mc']   = InWhichSign($data['p1'][20]) . '-' . InWhichHouse($data['p1'][20], $data['hc1']) . '-' . $data['p1'][20];

    return $result;
}

/**初始化本命盘
 * @param array $data
 * @param string $h_sys
 * @return array
 */
function getOriginalData($data = [], $h_sys = 'p')
{
    foreach ($data as $key => $line) {
        $row          = explode(',', $line);
        $planet[$key] = $row[0] * 1;
        $speed[$key]  = $row[1] * 1;
    }
    ;

    // 判断是日间盘还是夜间盘
    if ($planet[15] > $planet[21]) {
        if ($planet[0] <= $planet[15] and $planet[0] > $planet[21]) {
            $day_chart = true;
        } else {
            $day_chart = false;
        }
    } else
    if ($planet[0] > $planet[15] and $planet[0] <= $planet[21]) {
        $day_chart = false;
    } else {
        $day_chart = true;
    }

    $juno = $planet[13]; // 婚神星
    // 计算福点位置
    if ($day_chart == true) {
        $fort = $planet[15] + $planet[1] - $planet[0];
    } else {
        $fort = $planet[15] - $planet[1] + $planet[0];
    }

    if ($fort >= 360) {
        $fort -= 360;
    }

    if ($fort < 0) {
        $fort += 360;
    }

    // 计算宿命点度数
    $vert = $planet[30];

    $hc = [];
    // 此处 加入特殊分宫制   整宫制
    if ($h_sys == 'w') {
        $hc[1] = floor($planet[15] / 30) * 30;
        for ($i = 1; $i <= 14; $i++) {
            $house = $hc[1] + ($i - 1) * 30;
            if ($house > 360) {
                $house -= 360;
            }
            $hc[$i] = $house;
            unset($planet[14 + $i]);
        }
    } else {
        for ($i = 1; $i <= 14; $i++) {
            $hc[$i] = $planet[14 + $i];
            unset($planet[14 + $i]);
        }
    }
    unset($hc[13]);
    unset($hc[14]);
    unset($planet[29]);
    unset($planet[30]);

    $planet[13] = $juno; // 婚神星
    $planet[14] = $fort; // 福点
    $planet[15] = $vert; // 宿命点
    $planet[16] = $planet[12] > 180 ? $planet[12] - 180 : $planet[12] + 180; // 增加南交点
    // 加四轴 放入行星组中
    $planet[17] = $hc[1]; // 上升点
    $planet[18] = $hc[4]; // 天底
    $planet[19] = $hc[7]; // 下降点
    $planet[20] = $hc[10]; // 天顶

    $retro = getRetroData($speed);

    $returnData = ['rx1' => $retro, 'p1' => $planet, 'hc1' => $hc, 'speed' => $speed];

    return $returnData;
}

/**
 * 获取是否逆行数据
 * @param  [type] $speed [description]
 * @return [type]        [description]
 */
function getRetroData($speed)
{
    $retro = '';

    for ($i = 0; $i <= 13; $i++) {
        if (@$speed[$i] < 0) {
            $retro .= "R";
        } else {
            $retro .= " ";
        }

    }

    return $retro;
}

/**
 * 获取基础时间
 * @param null $year
 * @param null $month
 * @param null $day
 * @param null $hour
 * @param null $minute
 * @param int $timezone
 * @return false|int
 */
function getTheBaseTime($year = null, $month = null, $day = null, $hour = null, $minute = null, $timezone = 8)
{
    if (isSummerTime($hour, $minute, 0, $month, $day, $year)) {
        $hour--; // 夏令时减一小时
    }

    if ($timezone >= 0) {
        $whole    = floor($timezone);
        $fraction = $timezone - floor($timezone);
    } else {
        $whole    = ceil($timezone);
        $fraction = $timezone - ceil($timezone);
    }
    $hour   = $hour - $whole;
    $minute = $minute - ($fraction * 60);

    $time = mktime($hour, $minute, 0, $month, $day, $year);

    return $time;
}

/**
 * solar eclipse
 * lunar eclipse
 * @param int $time 天象时间
 * @param int $timezone 时区
 * @param int $type 类型 0日食 1月食
 * @return false|int
 */
function getEclipse(int $time = 0, int $timezone = 8, $type = 0)
{
    $start_time = [
        mktime(2, 0, 0, 5, 4, 1986),
        mktime(2, 0, 0, 4, 12, 1987),
        mktime(2, 0, 0, 4, 10, 1988),
        mktime(2, 0, 0, 4, 16, 1989),
        mktime(2, 0, 0, 4, 15, 1990),
        mktime(2, 0, 0, 4, 14, 1991),
    ];
    $end_time = [
        mktime(2, 0, 0, 9, 14, 1986),
        mktime(2, 0, 0, 9, 13, 1987),
        mktime(2, 0, 0, 9, 11, 1988),
        mktime(2, 0, 0, 9, 17, 1989),
        mktime(2, 0, 0, 9, 16, 1990),
        mktime(2, 0, 0, 9, 15, 1991),
    ];

    $change = 0;

    for ($i = 0; $i < 6; $i++) {
        if ($time > $start_time[$i] && $time < $end_time[$i]) {
            $change -= 3600;
        }
    }

    $change -= $timezone * 3600;

    $time += $change;

    $utdatenow = strftime("%d.%m.%Y", $time);

    if ($type == 1) {
        $exec_str = config('astrolog.prefix') . " -b{$utdatenow} -lunecl -eswe -g, -head"; // 月食
    } else {
        $exec_str = config('astrolog.prefix') . " -b{$utdatenow} -solecl -eswe -g, -head"; // 日食
    }
    exec($exec_str, $out);

    $arr = explode(',', $out[1]);
   //var_dump($out);die;
    $time_b     = trim($arr[1]);
    $time_a     = trim($arr[2]);
    $time_a     = substr($time_a, 0, -2);
    $time_a_arr = explode(':', $time_a);
    $time_a     = $time_a_arr[0] * 1 . '.' . $time_a_arr[1] * 1 . '.' . $time_a_arr[2] * 1;

    $timestamp = strtotime($time_b . ' ' . $time_a);
    $timestamp -= $change;
    

    return $timestamp;
}

/**
 * 检测是否构成T三角
 * @param array $t_square
 * @param int $pid
 * @return bool
 */
function is_in_t_square(array $t_square, int $pid)
{
    if (!empty($t_square)) {
        foreach ($t_square as $t_s) {
            if (in_array($pid, $t_s)) {
                return true;
            }
        }
    }
    return false;
}

/**获取当前月份天数
 * @param $time
 */
function month_days($time)
{
    //获取当前月份天数
    $j          = date("t", $time);
    $start_time = strtotime(date('Y-m-01', $time)); //获取本月第一天时间戳
    $month      = [];
    for ($i = $start_time; $i < strtotime('+1 month', $start_time);) {
        $month[] = $i; //每隔一天赋值给数组
        $i       = strtotime('+1 day', $i);
        //每隔一天赋值给数组
    }
    return $month;
}
/**
 * 检测是否有订单超时未支付
 * 超时时间为一天：24小时
 * 进行关闭订单操作，
 * @param int $uid
 * @return bool
 * @throws \Exception
 * @throws \Exception\PDOException
 */

function check_overtime($uid = 0)
{  
    $orderModel = (new App\Models\Api\Orders());
    $orders = (new Orders())->UserUnpairOrder($uid);
     if (is_array($orders) && !empty($orders))
    {
        $idArray = [];
        $nowTime = time();
        foreach ($orders as $k => $v)
        {
            // 计算订单超时时间
            $overtime = strtotime("+24hours", $v['create_time']);

            if ($nowTime > $overtime) $idArray[] = $v['order_id'];
        }
        if (!empty($idArray))
        {
            try
            {
                $orderModel->whereIn('order_id', $idArray)->update(['status' => 2]);
                //删除用户所有未支付订单缓存
                \Cache::forget('u' . $uid . $orderModel::USER_UNPAIR_ORDER);
                // 更新用户所有未支付订单缓存
                foreach ($idArray as $id)
                {
                    $orderModel->rm_cache(['uid' => $uid, 'type' => 2, 'order_id' => $id, 'status' => 3]);
                }

            }
            catch (\Exception $e)
            {
               \Log::info('check_overtime error:' . $e->getMessage());
            }
        }
    }
}



/**关联数组去重复
 * @param $array
 * @param bool $recursion
 * @return array
 */
function super_unique($array, $recursion = false)
{
    // 序列化数组元素,去除重复
    $result = array_map('unserialize', array_unique(array_map('serialize', $array)));
    // 递归调用
    if ($recursion) {
        foreach ($result as $key => $value) {
            if (is_array($value)) {
                $result[$key] = super_unique($value);
            }
        }
    }
    return $result;
}

function getPaginatorData($total, $page = 1, $listrows = 10)
{
    $per_page     = $listrows; // 当前栏目每页文章总数
    $current_page = $page; // 当前栏目文章起始页码
    $last_page    = ceil($total / $per_page); // 最后一页的页码

    $start = ($current_page - 1) * $per_page; // 开始id
    $end   = $listrows; // 分页长度

    $pagination = [
        'start'        => $start,
        'end'          => $end,
        'total'        => $total,
        'per_page'     => $per_page,
        'current_page' => $current_page,
        'last_page'    => $last_page,
        'data'         => [],
    ];

    return $pagination;
}

function Mod100($value = 0)
{
    return $value > 100 ? 100 : ($value < 0 ? 0 : $value);
}

/**
 * 订单商品初始化
 */
function InitOrdersGoods($map = [])
{
    $orders = (new Orders())->from('orders as o')
        ->select('o.id', 'o.gid as ogid', 'og.gid')
        ->join('orders_goods as og', 'o.id', '=', 'og.oid', 'LEFT')
        ->where(['uid' => $map['uid']])
        ->get();

    $array = [];

    foreach ($orders as $k => $v) {
        if ($v['ogid'] && !$v['gid']) {
            $array[] = ['oid' => $v['id'], 'gid' => $v['ogid']];
        }
    }

    try
    {

        DB::table('orders_goods')->insert($array);

    } catch (\Exception $e) {
        \Log::info('订单商品id初始化入库失败' . $e->getMessage());

    }
}

/**
 * 订单删除初始化
 */
function InitOrdersDel($map = [])
{
    $orders = (new Orders())->from('orders as o')
        ->select('o.status', 'o.is_del', 'o.pay_time')
        ->join('orders_goods as og', 'o.id', '=', 'og.oid', 'LEFT')
        ->where(['uid' => $map['uid']])
        ->get();
    $orders = json_decode(json_encode($orders, true), true);

    if (!empty($orders)) {
        foreach ($orders as $k => $v) {

            // 订单删除状态初始化
            if ($v['status'] == -1 && $v['is_del'] == 0) {
                try
                {

                    (new Orders())->where(['uid' => $map['uid']])->where('status', -1)->update(['is_del' => 1]);

                } catch (\Exception $e) {
                    \Log::info('订单删除初始化入库失败' . $e->getMessage());

                }
            }

            // 将已购买的订单状态还原为 1
            if ($v['pay_time'] > 0 && $v['status'] == -1) {
                try
                {

                    (new Orders())->where(['uid' => $map['uid']])->where('status', -1)->update(['status' => 1]);

                } catch (\Exception $e) {
                    \Log::info('订单删除初始化入库失败' . $e->getMessage());

                }
            }

        }
    }
}

/**检测网络是否连接
 * @param $url
 * @return bool
 */
function varify_url($url)
{
    $check = @fopen($url, "r");
    if ($check) {
        $status = true;
    } else {
        $status = false;
    }
    return $status;
}

/**获取运营活动时间
 * @return array
 * @throws db\exception\DataNotFoundException
 * @throws db\exception\ModelNotFoundException
 * @throws exception\DbException
 */
function get_active_time()
{
    //买一赠一,生时校正,占星地图
    $active_time = Cache::get('active_time_1');
//免费解锁
    $free_time = Cache::get('active_time_2');
   
    if ($active_time === null || $free_time === null) {
        $data = DB::table('app_operation_active')->get();
        $data = json_decode(json_encode($data, true), true);
        foreach ($data as $datum) {
            Cache::set('active_time_' . $datum['type'], $datum, 86400 * 7);
            if ($datum['type'] == 1) {
                $active_time = $datum;
            } elseif ($datum['type'] == 2) {
                $free_time = $datum;
            }
        }
    }

    return [
        // 活动时间范围
        'active_status' => $active_time['status'],
        //买一赠一,生时校正,占星地图
        'start'         => $active_time['start_time'],
        'end'           => $active_time['end_time'],
        //免费解锁 
        'free_status'   => $free_time['status'],
        'free_start'    => $free_time['start_time'],
        'free_end'      => $free_time['end_time'],
    ];
}

/**检测是否是活动时间
 * @return bool
 */
function checktime()
{
    $get_active_time = get_active_time();
    $start_time      = strtotime($get_active_time['start']);
    $end_time        = strtotime($get_active_time['end']);
    $time            = strtotime(date('Y-m-d H:i:s', time()));
    $status          = $get_active_time['active_status'];

    if ($time >= $start_time && $time <= $end_time && $status == 1) {
        return true;
    } else {
        return false;
    }
}

/**
 * 获取三限容许系数
 * @param int $orb 当前相位真实容许度
 * @return float|int
 */
function getThirdprogressedModulus($orb = 0)
{
    // 三次限容许系数
    // 1度内1
    if ($orb < 1) {
        $modulus = 1;
    } // 1-2度 0.95
    elseif ($orb < 2) {
        $modulus = 0.95;
    } // 2-3度 0.9
    elseif ($orb < 3) {
        $modulus = 0.9;
    } // 3-4度 0.85
    elseif ($orb <= 4) {
        $modulus = 0.85;
    } // 4-5度 0.8
    elseif ($orb <= 5) {
        $modulus = 0.8;
    } // 5度外 0.7
    else {
        $modulus = 0.7;
    }
    return $modulus;
}

/**
 * 获取行运容许系数
 * @param int $orb 当前相位真实容许度
 * @return float|int
 */
function getTransitsModulus($orb = 0)
{
    // 行运容许系数
    // 30分内 1
    if ($orb < 0.5) {
        $modulus = 1;
    } // 1度内 0.95
    elseif ($orb < 1) {
        $modulus = 0.95;
    } // 1.5内 0.85
    elseif ($orb < 1.5) {
        $modulus = 0.85;
    } // 2内 0.7
    else {
        $modulus = 0.7;
    }

    return $modulus;

}

/**获取一段时间范围内的具体所有时间
 * @param $start
 * @param $end
 */
function prDates($map = [])
{

    $start = $map['start'];
    $end   = $map['end'];
    $type  = $map['type'];

    $time = [];
    //判断时间类型  年/月/日
    switch ($type) {
        case 1:
            $dt_start = strtotime($start);
            $dt_end   = strtotime($end);
            //日
            while ($dt_start <= $dt_end) {
                $time[]   = date('Y-n-j', $dt_start);
                $dt_start = strtotime('+1 day', $dt_start);
            }
            break;
        case 2:
            $dt_start = strtotime($start);
            $dt_end   = strtotime($end);
            //月
            while ($dt_start <= $dt_end) {
                $time[]   = date('Y-n', $dt_start);
                $dt_start = strtotime('+1 month', $dt_start);
            }
            break;
        case 3:
            $dt_start = strtotime($start . '-1');
            $dt_end   = strtotime($end . '-1');
            //年
            while ($dt_start <= $dt_end) {
                $time[]   = date('Y', $dt_start);
                $dt_start = strtotime('+1 year', $dt_start);
            }
            break;
    }
    return $time;
}

/**将运势加入运算队列,一笔订单所有数据统一加入队列
 * @param array $map
 */
function fortune_redis_job($map = [])
{
    $order_id    = $map['order_id'];
    $oid         = $map['oid'];
    $recode_info = $map['recode_info'];
    $unlock_time = $map['unlock_time'];
    $o_status    = $map['ostatus'];
    $ftype       = $map['ftype'];
    $is_last     = isset($map['is_last']) ? $map['is_last'] : 1;

    switch ($ftype) {
        case 2:
            $fname = 'month';
            break;
        case 3:
            $fname = 'year';
            break;
        default:
            $fname = '';
            break;
    }
    if ($fname != '') {
        // 运势队列消费时需要的数据
        $jobData = [
            'oid'        =>$oid,
            'order_id'   => $order_id,
            'recode'     => $recode_info,
            'start_time' => $unlock_time,
            'type'       => $fname,
            'status'     => $o_status,
            'is_last'    => $is_last,
        ];

        $fortune_job_setting = config('fortune');

        $delay = $fortune_job_setting['delay'];
        if (getVip($recode_info[0]['uid']) >= 1) {
            $delay = 0;
        }
        queuePush($fortune_job_setting['task'], $jobData, $fortune_job_setting['queue'], $delay);
    }

    return;

}
/**
 * 将咨询师认证加入队列(队列数据只需要认证信息id)
 * @param array $map
 */
function counselor_identity_job($auth_id = 0)
{
    // 咨询师认证队列消费时需要的数据
    $queueConfig = config('queue');

    queuePush($queueConfig['identity_task'], $auth_id, $queueConfig['identity_queue'], $queueConfig['identity_delay']);
}

function getVip($uid = 0, $default = false)
{
    if (in_array($uid, config('vip'))) {
        return 1;
    }
    if (in_array($uid, config('vip'))) {
        return 2;
    }
    return $default;
}
/**
 * 保证星座id在范围内   1~12
 * @param int $sign
 * @return int
 */
function modSignId($sign = 0)
{
    return $sign < 1 ? 12 : ($sign > 12 ? 1 : $sign);
}
/**
 * 过去多久时间
 * @param int $dateTimeStamp 是一个时间毫秒，注意时间戳是秒的形式，在这个毫秒的基础上除以1000，就是十位数的时间戳。13位数的都是时间毫秒。
 * @param string $format 一年以上时，返回的时间格式
 * @return bool|false|string
 */
function timeago($dateTimeStamp = 0, $format = 'Y-m-d')
{
    $minute     = 1000 * 60; //把分，时，天，周，半个月，一个月用毫秒表示
    $hour       = $minute * 60;
    $day        = $hour * 24;
    $week       = $day * 7;
    $halfamonth = $day * 15;
    $month      = $day * 30;
    $now        = floor(microtime(true) * 1000); //获取当前时间毫秒
    $diffValue  = $now - $dateTimeStamp; //时间差
    if ($diffValue < 0) {
        return '';
    }
    $minC   = $diffValue / $minute; //计算时间差的分，时，天，周，月
    $hourC  = $diffValue / $hour;
    $dayC   = $diffValue / $day;
    $weekC  = $diffValue / $week;
    $monthC = $diffValue / $month;
    if ($monthC >= 1 && $monthC <= 3) {
        $result = intval($monthC) . "月前";
    } else if ($weekC >= 1 && $weekC <= 3) {
        $result = intval($weekC) . "周前";
    } else if ($dayC >= 1 && $dayC <= 6) {
        $result = intval($dayC) . "天前";
    } else if ($hourC >= 1 && $hourC <= 23) {
        $result = intval($hourC) . "小时前";
    } else if ($minC >= 1 && $minC <= 59) {
        $result = intval($minC) . "分钟前";
    } else if ($diffValue >= 0 && $diffValue <= $minute) {
        $result = "刚刚";
    } else {
        $result = date($format, $dateTimeStamp);
    }
    return $result;

}
 /**
     * 生成唯一订单号  011806192149570386 01生时校正 02运势 03占星地图 04占星视频 05问答 06围观
     * @param $order_type 订单号类型 1生时校正 2运势 3占星地图 4占星视频 5问答 6围观 7充值 8VIP
     * @return string
     */
    function createOrderNumber($order_type)
    {
        $orderNumber = str_pad($order_type, 2, '0', STR_PAD_LEFT) . date('YmdHis') . str_pad(rand(1, 9999), 4, '0', STR_PAD_LEFT);

        return $orderNumber;
    }

    /**
     * 下单使用的商户配置id
     * @param $trade_type 支付方式   1=>支付宝，2=>微信支付，5=>京东支付，6=>微信公众号支付，7=>支付宝手机网页支付，8=>微信H5网页支付
     * @return int
     */
   function getAccountId($trade_type)
    {
        switch ($trade_type)
        {
            case 1:
                $account = intval(config('alipay.default'));
                break;
            case 2:
                $account = intval(config('wxpay.default'));
                break;
            case 5:
                $account = intval(config('jdpay.default'));
                break;
            case 6:
                $account = intval(config('wxpay.default'));
                break;
            case 7:
                $account = intval(config('alipay.default'));
                break;
            case 8:
                $account = intval(config('wxpay.default'));
                break;
            default:
                $account = 1;
                break;
        }

        return $account;
    }

    /**
     * 获取vip价格
     * @param $uid
     * @param $price
     * @param $rid
     * @param $rids
     * @return float
     * @throws exception\ApiException
     */
 function getVipPrice($uid, $price, $rid, $rids)
    {
        $vipLevel = getVip($uid);
        // 获取当前用户的档案id
        $selfId = (new Recode())->getSelfRecode(['uid' => $uid]);
        if ($rids)
        {
            $rids = explode(',', $rids);
        }

        if ($vipLevel === 1 || ($vipLevel > 1 && ($rid == $selfId['id'] || (count($rids) == 1 && $rids[0] == $selfId['id']))))
        {
            $price = 0.01;
        }
        // 返回最终价格
        return round($price, 2);
    }

/**
 * 获取不同商品的活动折扣
 * @param $gids
 */
function active($gid = 0, $start_time = '2019-5')
{
    $now_time = time();
    $arr = [
        'discount' => 0,
        'indexGift' => false//首页大礼包开关
    ];
    if ($gid)
    {
        /**
         * 六一活动
         */
        // ①若是六月一日当天且够买的六月运势打七折
        if (strtotime('2019-06-01 00:00:00') <= $now_time && $now_time < strtotime('2019-06-01 23:59:59') && $gid == 20 && $start_time == '2019-06')
        {
            $arr['discount'] = 0.7;
        }
        //②若是6.2到6.15(包含6.15)月度运势打九折
        if (strtotime('2019-05-02 00:00:00') <= $now_time && $now_time < strtotime('2019-06-15 23:59:59') && in_array($gid, config('app.month_id')))
        {
            $arr['discount'] = 0.9;
        }
        //③6.(7,8,9) 当天购买占星地图打九折
        if (strtotime('2019-06-07 00:00:00') <= $now_time && $now_time < strtotime('2019-06-09 23:59:59') && in_array($gid, config('app.acg_id')))
        {
            $arr['discount'] = 0.9;
        }
    }
    return $arr;
}

/**
 * 封闭curl的调用接口
 * @param $url $url(网址）
 * @param int $ifpost $ifpost(用post传值时需调为1)
 * @param string $datafields $datafields(post的数据)
 * @param string $cookiefile
 * @param bool $v
 * @return bool|string
 */
function curl($url, $ifpost = '0', string $datafields='', $cookiefile = '', $v = false)
{
    $header =  array('Content-type: application/json');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    //curl_setopt($ch, CURLOPT_HEADER, $v);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    $ifpost && curl_setopt($ch, CURLOPT_POST, $ifpost);
    $ifpost && curl_setopt($ch, CURLOPT_POSTFIELDS, $datafields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
    $cookiefile && curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
    $cookiefile && curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $r = curl_exec($ch);
    curl_close($ch);
    return $r;
}

/**
 * 内容安全审查
 *
 * @param string $content 待审查的内容
 * @param string $type 内容类型，可选值：text、image
 *
 * @return array 审查结果
 *
 * @throws InvalidArgumentException 无效的内容类型
 * @throws RuntimeException API 调用错误
 */

function contentCensor($content, $type = 'text')
{
    $aipContentCensor = new AipContentCensor('55691200','fkdxdIr31qLTElQqmjtmgfbe','jcxRtLMS5tvqo17OmwUDXczDAW0O74yi');

  if ($type === 'text') {
        $result = $aipContentCensor->textCensorUserDefined($content);
    } elseif ($type === 'image') {
        $result = $aipContentCensor->imageCensorUserDefined($content);
    } else {
        throw new InvalidArgumentException('Invalid content type: ' . $type);
    }

    if (isset($result['error_code'])) {
        // 处理 API 调用错误
        throw new RuntimeException($result['error_msg'], $result['error_code']);
    }
     $response = ['status' => 0, 'msg' => ''];
   // 直接在这里进行审查结果的公共处理
    if (isset($result['conclusionType'])) {
        $conclusionType = $result['conclusionType'];
        
        if ($conclusionType === 2) {
            $msg = isset($result['data'][0]['msg']) ? $result['data'][0]['msg'] : '内容不合规';
            $response['status'] = $conclusionType;
            $response['msg'] = $msg;
        } elseif ($conclusionType === 3 || $conclusionType === 4) {
            // 疑似和失败的写数据库，人工审核
            $msg = isset($result['data'][0]['msg']) ? $result['data'][0]['msg'] : '内容不合规';
            $response['status'] = $conclusionType;
            $response['msg'] = $msg;
        }
    }
    
   return $response;
}
/**
 * 获取对应时区的时间
 * @param string $dateformat 时间格式
 * @param int $timestamp 时间戳
 * @param float $startTimezone 当前时间时区
 * @param float $endTimezone 需要转换成的时区时间
 * @param bool $isFormat 时间是否格式化
 * @return string
 * @throws Exception
 */
function gmdateModify($dateformat = 'Y-m-d H:i:s', $timestamp = 0, $startTimezone = 8.0, $endTimezone = 8.0, $isFormat = true)
{
    if (empty($timestamp))
    {
        $timestamp = time();
    }
    $timestamp = $timestamp + (8 - (float)$startTimezone) * 3600; // 先转换成东八区时间戳

    $result = gmdate($dateformat, $timestamp + (float)$endTimezone * 3600);
    if (!$isFormat)
    {
        $result = strtotimeModify('U', $result);
    }
    return $result;
}
/**
 * 日期处理，默认转为时间戳
 * @param string $date 年-月-日 时:分:秒
 * @param string $expire_time
 * @param string $format 格式 Y-m-d / U
 * @param string $timezone 时区
 * @return int
 * @demo strtotimeModify('2020-06-10', '13:48:54','+1 month','Y-m-d');
 * @throws Exception
 */
function strtotimeModify($format = 'U', string $date = '', string $expire_time = '', $timezone = 'PRC')
{
    if (count(explode('-', $date)) == 1)
    {
        $date .= '-1';
    }
    $datetime = new \DateTime($date, new DateTimeZone($timezone));
    $datetime->setTimezone(new DateTimeZone($timezone));
    if ($expire_time)
    {
        $datetime->modify($expire_time);
    }
    return $datetime->format($format);
}
/**
 * 数组key和value保持一致
 * @param $data
 * @return array
 */
function array_flip_key_value($data)
{
    $array = [];
    foreach ($data as $id)
    {
        $array[$id] = $id;
    }
    return $array;
}
